package edu.ccut.saturn.studio.logic.model.drop;

import java.util.Map;

public abstract class DropHandlerFactory {
	private static final String DROP_HANDLER_FACTORY_DOT = ".";
	
	protected Map<String, DropHandler> dropHandleMap;
	public DropHandlerFactory() {
		this.initalDropHandle();
	}
	public DropHandler getShapeHandler(String postfix) {
		if(this.dropHandleMap.get(this.getPostfix(postfix)) != null){
			return this.dropHandleMap.get(this.getPostfix(postfix));
		}
		return null;
	}
	
	@SuppressWarnings("unchecked")
	protected abstract void initalDropHandle();

	private String getPostfix(String filePath) {
		String firstPostfix = null;
		
		try {
			int index = filePath.lastIndexOf(DROP_HANDLER_FACTORY_DOT);
			firstPostfix = filePath.substring(index, filePath.length());
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
		
		return firstPostfix;
	}
}
